//
//  RenHeTeacherViewController.m
//  BigToBig
//
//  Created by yi liu on 16/7/29.
//  Copyright © 2016年 cn.cloudtp. All rights reserved.
//
#define HORIZONTAL [[UIScreen mainScreen] bounds].size.width / 320
#define VERTICAL [[UIScreen mainScreen] bounds].size.height / 568
#import "RenHeTeacherViewController.h"
#import "HomeFunctionView.h"
#import "RenHeTeacherCell.h"
#import "RenHeTeacherDetailController.h"
#import "RenheModel.h"

@interface RenHeTeacherViewController ()
<
UITableViewDelegate,
UITableViewDataSource
>

@property (nonatomic , strong)HomeFunctionView *homeFunctionView;
@property (nonatomic , strong)UITableView *mainTableView;
@property(nonatomic,strong)NSMutableArray *teacherArr;
@property(nonatomic,strong)MBProgressHUD *hud;
@end

@implementation RenHeTeacherViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createView];
    
    [self createDate];
      self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];

}

#pragma mark 获取数据
- (void)createDate{
    
    [HttpTool postWithURL:@"http://61.135.176.43:6080/bigtobig/mentor/get_approved_mentors?limit=10&offset=0" params:nil success:^(id json) {
        
        self.teacherArr = [NSMutableArray array];
        for (NSDictionary *dic in json[@"MentorList"]) {
            
            RenheModel *renhe = [[RenheModel alloc] init];
            [renhe setValuesForKeysWithDictionary:dic];
            [self.teacherArr addObject:renhe];
            self.hud.hidden = YES;
            
        }
        [self.mainTableView reloadData];
        
    } failure:^(NSError *error) {
        
    }];
    
}

- (void)createView{
    self.homeFunctionView = [[HomeFunctionView alloc]initWithFrame:CGRectMake(0, 64, kScreenWidth, 40)];
    [self.view addSubview:self.homeFunctionView];
    
    // 创建mainTableView
    self.mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 104, kScreenWidth, kScreenHeight - 104 - 49)];
    [self.view addSubview:self.mainTableView];
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    [self.mainTableView registerClass:[RenHeTeacherCell class] forCellReuseIdentifier:NSStringFromClass([RenHeTeacherCell class])];
    self.mainTableView.separatorStyle = NO;
    self.mainTableView.bounces = NO;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100 * VERTICAL;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.teacherArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RenheModel *renHe = self.teacherArr[indexPath.row];
    RenHeTeacherCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([RenHeTeacherCell class]) forIndexPath:indexPath];
    
    cell.markArray = @[@"电子商务",@"生活服务",@"医疗健康",@"新兴技术"];
    
    [cell.headImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://61.135.176.43:6080/data/HeadPortrait/%@",renHe.headImage]] placeholderImage:[UIImage imageNamed:@"touxiang"]];
    cell.nameLabel.text = renHe.name;
    cell.jobLabel.text = renHe.jobTitle;
    
    if ([[renHe.selfIntroduction stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
        cell.describeLabel.text = @"还没有写自我介绍...";
    }else{
        cell.describeLabel.text = renHe.selfIntroduction;
    }
    cell.projectLabel.text = [NSString stringWithFormat:@"%@%@",@"  指导项目 : ",renHe.relation_user_count];
    cell.studentLabel.text = [NSString stringWithFormat:@"%@%@",@"  指导学员 : ",renHe.relation_project_count];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    RenHeTeacherDetailController *teacherDetailC = [[RenHeTeacherDetailController alloc]init];
    RenheModel *renhee = self.teacherArr[indexPath.row];
    teacherDetailC.renhe = renhee;
    self.tabBarController.tabBar.hidden = YES;
    [self.navigationController pushViewController:teacherDetailC animated:YES];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
